home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CICA Windows Explosion!
/
The CICA Windows Explosion! - Disc 2.iso
/
programr
/
ole2book.zip
/
CHAP07.ZIP
/
CHAP07
/
DATATRAN
/
DATAOBJ.CPP
next >
Wrap
C/C++ Source or Header
|
1993-04-23
|
4KB
|
203 lines
/*
* DATAOBJ.CPP
* Data Transfer Object for Chapter 7
*
* Implementation of the CDataObject for the Data Transfer Component Object.
*
* Copyright (c)1993 Microsoft Corporation, All Rights Reserved
*
* Kraig Brockschmidt, Software Design Engineer
* Microsoft Systems Developer Relations
*
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
*/
#include "dataobj.h"
extern HINSTANCE g_hInst;
/*
* CDataObject::CDataObject
* CDataObject::~CDataObject
*
* Parameters (Constructor):
* punkOuter LPUNKNOWN of a controlling unknown, if it exists.
* pfnDestroy LPFNDESTROYED to call when an object is destroyed.
*/
CDataObject::CDataObject(LPUNKNOWN punkOuter, LPFNDESTROYED pfnDestroy)
{
m_cRef=0;
m_punkOuter=punkOuter;
m_pfnDestroy=pfnDestroy;
m_hList=NULL;
//NULL any contained interfaces initially.
m_pIDataObject=NULL;
return;
}
CDataObject::~CDataObject(void)
{
if (NULL!=m_pIDataObject)
delete m_pIDataObject;
Purge();
if (NULL!=m_hList)
DestroyWindow(m_hList);
return;
}
/*
* CDataObject::FInit
*
* Purpose:
* Performs any intiailization of a CDataObject that's prone to failure
* that we also use internally before exposing the object outside.
*
* Parameters:
* None
*
* Return Value:
* BOOL TRUE if the function is successful, FALSE otherwise.
*/
BOOL CDataObject::FInit(void)
{
LPUNKNOWN pIUnknown=(LPUNKNOWN)this;
if (NULL!=m_punkOuter)
pIUnknown=m_punkOuter;
//Allocate contained interfaces.
m_pIDataObject=new CImpIDataObject(this, pIUnknown);
if (NULL==m_pIDataObject)
return FALSE;
m_hList=CreateWindow("listbox", "renderings", WS_POPUP | LBS_OWNERDRAWFIXED
, 0, 0, 100, 100, HWND_DESKTOP, NULL, g_hInst, NULL);
if (NULL==m_hList)
return FALSE;
return TRUE;
}
/*
* CDataObject::Purge
*
* Purpose:
* Cleans out all entries in our listbox.
*
* Parameters:
* None
*
* Return Value:
* None
*/
void CDataObject::Purge(void)
{
UINT i, cItems;
LPRENDERING pRen;
DWORD cb;
if (NULL==m_hList)
return;
cItems=(UINT)SendMessage(m_hList, LB_GETCOUNT, 0, 0L);
for (i=0; i < cItems; i++)
{
cb=SendMessage(m_hList, LB_GETTEXT, i, (LPARAM)(LPVOID)&pRen);
if (sizeof(LPRENDERING)==cb)
{
/*
* Release the data completely being sure to reinstate
* the original pUnkForRelease.
*/
pRen->stm.pUnkForRelease=pRen->pUnkOrg;
ReleaseStgMedium(&pRen->stm);
delete pRen;
}
}
SendMessage(m_hList, LB_RESETCONTENT, 0, 0L);
return;
}
/*
* CDataObject::QueryInterface
* CDataObject::AddRef
* CDataObject::Release
*
* Purpose:
* IUnknown members for CDataObject object.
*/
STDMETHODIMP CDataObject::QueryInterface(REFIID riid, LPVOID FAR *ppv)
{
*ppv=NULL;
if (IsEqualIID(riid, IID_IUnknown))
*ppv=(LPVOID)this;
if (IsEqualIID(riid, IID_IDataObject))
*ppv=(LPVOID)m_pIDataObject;
//AddRef any interface we'll return.
if (NULL!=*ppv)
{
((LPUNKNOWN)*ppv)->AddRef();
return NOERROR;
}
return ResultFromScode(E_NOINTERFACE);
}
STDMETHODIMP_(ULONG) CDataObject::AddRef(void)
{
return ++m_cRef;
}
STDMETHODIMP_(ULONG) CDataObject::Release(void)
{
ULONG cRefT;
cRefT=--m_cRef;
if (0==m_cRef)
{
/*
* Tell the housing that an object is going away so it can
* shut down if appropriate.
*/
if (NULL!=m_pfnDestroy)
(*m_pfnDestroy)();
delete this;
}
return cRefT;
}